<?php
/*
	本插件：$this->model('model')->方法名();
	其他地方调用：model('jy_faceid/model')->方法名();
*/
namespace jy_faceid;
defined('BY_JYA') or exit('error');
require_once ROOT_PLUGIN.'jy_faceid/vendor/autoload.php';
use \TencentCloud\Common\Credential;
use \TencentCloud\Common\Profile\ClientProfile;
use \TencentCloud\Common\Profile\HttpProfile;
use \TencentCloud\Common\Exception\TencentCloudSDKException;
use \TencentCloud\Faceid\V20180301\FaceidClient;
use \TencentCloud\Faceid\V20180301\Models\IdCardVerificationRequest;
use \TencentCloud\Faceid\V20180301\Models\IdCardOCRVerificationRequest;
class api extends \plugin{
	public function checkinfo($params=array(),$noexi=false){
		$setting=plugin('jy_faceid')->plugin_setting('basic');
		if(!$setting['isopen']){
		    if(!$noexi){
                exi('实名核实未启用！','error');
            }else{
		        return false;
            }
        }
		if(!$setting['apiid'] || !$setting['apikey']){
			exi('请联系管理员，设置基本参数！','error');
		}
		$cred = new Credential($setting['apiid'], $setting['apikey']);
		// 实例化一个http选项，可选的，没有特殊需求可以跳过
		$httpProfile = new HttpProfile();
		$httpProfile->setEndpoint("faceid.tencentcloudapi.com");
		// 实例化一个client选项，可选的，没有特殊需求可以跳过
		$clientProfile = new ClientProfile();
		$clientProfile->setHttpProfile($httpProfile);
		// 实例化要请求产品的client对象,clientProfile是可选的
		$client = new FaceidClient($cred, "", $clientProfile);

		// 实例化一个请求对象,每个接口都会对应一个request对象
		$req = new IdCardOCRVerificationRequest();
		$params = array(
			'IdCard'=>$params['cardnum'],
			'Name'=>$params['realname'],
			'ImageUrl'=>tomedia($params['cardimg1']),
		);
		$req->fromJsonString(ijson_encode($params));
		// 返回的resp是一个IdCardVerificationResponse的实例，与请求对象对应
		$resp = $client->IdCardOCRVerification($req);

		// 输出json格式的字符串回包
		$data=$resp->toJsonString();
		$data=json_decode($data,true);
		//print_r($data);exit;
		//$data['Result']=0;
		if($data['Result']){
			exi('身份核实失败：'.$data['Description'],'error');
		}
        return $data;
    }
}
?>